1. /* sxmshift.cpp by K.Tsuru */
  2. // function ID = 506 BRADIX
  3. /********************
  4. SDecimal class
  5. bit shift x --> x*2^p
  6. *********************/
  7. #ifndef SN_H
  8. #include "sn.h"
  9. #endif
  10. SDecimal& SDecimal::BitShift(long p){
  11. if(!p || !Sign()) return *this;
  12. long r, top, f0, shift;
  13. int err = 0;
  14. fType mult, div;
  15. if(p > 0){
  16. shift = p/(long)BRADIX_BITS;
  17. r = p - shift*(long)BRADIX_BITS;// r >= 0
  18. mult = 1 << (int)r;
  19. top = (long)aTail - shift; // top figure position after shift.
  20. if(top < 0) err = 1;
  21. else if( top == 0 ){
  22. f0 = (long)figure(0)*mult;
  23. if(f0 >= BRADIX) err = 1; // first figure >= BRADIX
  24. }
  25. if(err) SetError(OVERFLOW_ERR, "SX BitShift", 506);
  26. if(shift) ShiftArray(-(int)shift);
  27. if(r) XsMult(*this, mult, *this); // mult > 1
  28. return *this;
  29. }
  30. // p < 0
  31. shift = -p/(long)BRADIX_BITS;
  32. r = -(BRADIX_BITS*shift + p);
  33. div = 1 << (int)r;
  34. if( shift + (long)aTail >= (long)CurrentMaxSize() ) SetZero();
  35. else {
  36. if(shift) ShiftArray((int)shift);
  37. if(r) XsDiv(*this, div, *this);
  38. }
  39. return *this;
  40. }

sxmshift.cpp : last modifiled at 2017/03/13 14:32:02(1,073 bytes)
created at 2015/12/22 16:09:56
The creation time of this html file is 2017/10/27 15:45:59 (Fri Oct 27 15:45:59 2017).